﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CoreEx.Common.Extensions;
using LinFu.IoC.Configuration;

namespace CoreEx.Database.Query.Implementation
{
    [Implements(typeof(IExpressionList))]
    public class ExpressionList : ExpressionBase, IExpressionList
    {
        private readonly IList<IExpression> _expressions = new List<IExpression>();

        

        /// <summary>
        /// Adds a <see cref="IExpression"/> to the list.
        /// </summary>
        /// <param name="expression">The <see cref="IExpression"/> to add to the list.</param>        
        public IExpressionList Add(IExpression expression)
        {
            _expressions.Add(expression);
            return this;
        }

        /// <summary>
        /// Adds a list of <see cref="IExpression"/> instances to the list.
        /// </summary>
        /// <param name="expressions"></param>        
        public IExpressionList AddRange(IEnumerable<IExpression> expressions)
        {
            expressions.ForEach(_expressions.Add);
            return this;
        }

        /// <summary>
        /// Gets the list that contains <see cref="IExpression"/> instances.
        /// </summary>
        public IEnumerable<IExpression> Expressions
        {
            get { return _expressions; }
        }
    }
}
